<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="125px"
    >
      <el-form-item label="组织机构代码证号" prop="orgCode">
        <el-input
          v-model="queryParams.orgCode"
          placeholder="请输入组织机构代码证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业名称" prop="orgName">
        <el-input
          v-model="queryParams.orgName"
          placeholder="请输入企业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['qyxy:jlscore:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['qyxy:jlscore:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['qyxy:jlscore:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['qyxy:jlscore:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row> -->

    <el-table
      v-loading="loading"
      :data="jlscoreList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="组织机构代码证号" align="center" prop="borgCode" />
      <el-table-column label="企业名称" align="center" prop="orgName" />
      <el-table-column label="得分" align="center" prop="score" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-notebook-2"
            @click="handleUpdate(scope.row)"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改监理企业得分对话框 -->
    <el-dialog
      :title="title"
      :before-close="cancel"
      :visible.sync="open"
      width="1000px"
      append-to-body
    >
      <h1>企业得分 : {{ detail.score }}</h1>
      <h2>资质信息 :</h2>
      <el-table :data="detail.list" style="width: 100%">
        <el-table-column type="expand">
          <template slot-scope="props">
            <h3>缺少人员 : {{ props.row.shortOfCount }}</h3>
            <h3>减分 : {{ props.row.reduceScore }}</h3>
            <template
              v-if="props.row.quaRank == '甲级' || props.row.quaRank == '乙级'"
            >
              <template v-if="JSON.parse(props.row.useZj).length > 0">
                <b>资质使用注册造价工程师 : {{JSON.parse(props.row.useZj).length}} 人</b>
                <el-table
                  :data="JSON.parse(props.row.useZj)"
                  style="width: 100%"
                >
                  <el-table-column label="姓名" prop="pname"> </el-table-column>
                  <el-table-column label="身份证" prop="idNum">
                  </el-table-column>
                </el-table>
                <hr />
              </template>
              <template v-if="JSON.parse(props.row.useJz).length > 0">
                <b>资质使用一级注册建造师 : {{JSON.parse(props.row.useJz).length}}人</b>
                <el-table
                  :data="JSON.parse(props.row.useJz)"
                  style="width: 100%"
                >
                  <el-table-column label="姓名" prop="pname"> </el-table-column>
                  <el-table-column label="身份证" prop="idNum">
                  </el-table-column>
                </el-table>
                <hr />
              </template>

              <template v-if="JSON.parse(props.row.useJzh).length > 0">
                <b>资质使用一级注册建筑师 : {{JSON.parse(props.row.useJzh).length}}人</b>
                <el-table
                  :data="JSON.parse(props.row.useJzh)"
                  style="width: 100%"
                >
                  <el-table-column label="姓名" prop="pname"> </el-table-column>
                  <el-table-column label="身份证" prop="idNum">
                  </el-table-column>
                </el-table>
                <hr />
              </template>
              <template v-if="JSON.parse(props.row.useJg).length > 0">
                <b>资质使用一级注册结构工程师 : {{JSON.parse(props.row.useJg).length}}人</b>
                <el-table
                  :data="JSON.parse(props.row.useJg)"
                  style="width: 100%"
                >
                  <el-table-column label="姓名" prop="pname"> </el-table-column>
                  <el-table-column label="身份证" prop="idNum">
                  </el-table-column>
                </el-table>
                <hr />
              </template>
              <template v-if="JSON.parse(props.row.useJl).length > 0">
                <b>资质使用注册监理工程师 :  {{JSON.parse(props.row.useJl).length}}人</b>
                <el-table
                  :data="JSON.parse(props.row.useJl)"
                  style="width: 100%"
                >
                  <el-table-column label="姓名" prop="pname"> </el-table-column>
                  <el-table-column label="身份证" prop="idNum">
                  </el-table-column>
                </el-table>
                <hr />
              </template>
            </template>
            <template v-else>
              <template v-if="JSON.parse(props.row.useJl).length > 0">
                <b>资质使用注册监理工程师 : {{JSON.parse(props.row.useJl).length}}人</b>
                <el-table
                  :data="JSON.parse(props.row.useJl)"
                  style="width: 100%"
                >
                  <el-table-column label="姓名" prop="pname"> </el-table-column>
                  <el-table-column label="身份证" prop="idNum">
                  </el-table-column>
                </el-table>
                <hr />
              </template>
            </template>
          </template>
        </el-table-column>
        <el-table-column label="资质名称" prop="quaName"> </el-table-column>
        <el-table-column label="资质类别" prop="quaType"> </el-table-column>
        <el-table-column label="等级" prop="quaRank"> </el-table-column>
        <el-table-column label="是否符合标准" prop="isConformTo">
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listJlscore,
  getJlscore,
  delJlscore,
  addJlscore,
  updateJlscore,
  exportJlscore,
} from "@/api/qyxy/jlscore";

export default {
  name: "Jlscore",
  components: {},
  data() {
    return {
      detail: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 监理企业得分表格数据
      jlscoreList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orgCode: null,
        orgName: null,
        score: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询监理企业得分列表 */
    getList() {
      this.loading = true;
      listJlscore(this.queryParams).then((response) => {
        this.jlscoreList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orgCode: null,
        orgName: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        score: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加监理企业得分";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      const orgCode = row.borgCode;
      const orgName = row.orgName;
      getJlscore(id).then((response) => {
        this.detail = response.data;
        this.open = true;
        this.title = orgName + "[" + orgCode + "]" + "得分明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateJlscore(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addJlscore(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除监理企业得分编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delJlscore(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有监理企业得分数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportJlscore(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
  },
};
</script>
